package com.common.base;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

public class BaseAction extends ActionSupport {

	protected HttpServletRequest  request;
	protected HttpServletResponse response;
	protected HttpSession session;
	protected String pager;
	protected Logger log = Logger.getLogger(this.getClass());

	public BaseAction(){
		super();
	}

	protected String topager(String pager){
		this.pager=pager;
		return "topager";
	}
	protected String redirect(String pager){
		this.pager=pager;
		return "redirect";
	}
	
	/**
	 * <li>@方法说明:
	 * <li>@return
	 * <li>@创建人:王剑
	 * <li>@创建日期:2010-5-27
	 * <li>@修改人: 
	 * <li>@修改日期:
	 * <li>@详细说明: /uphold
	 */
	protected String getContextPath(){
		return this.getRequest().getContextPath();
	}
	
	/**
	 * <li>@方法说明:
	 * <li>@return
	 * <li>@创建人:王剑
	 * <li>@创建日期:2010-5-27
	 * <li>@修改人: 
	 * <li>@修改日期:
	 * <li>@详细说明: http://125.64.38.141:80/uphold
	 */
	protected String getBasePath(){
		String basePath = this.getRequest().getScheme() + "://"
		+ this.getRequest().getServerName() + ":" + this.getRequest().getServerPort()
		+ getContextPath() + "";
		return basePath;
	}
	/**
	 * <li>@方法说明:
	 * <li>@return
	 * <li>@创建人:王剑
	 * <li>@创建日期:2010-5-27
	 * <li>@修改人: 
	 * <li>@修改日期:
	 * <li>@详细说明: "D:\\Javatools\\apache-tomcat-6.0.26\\apache-tomcat-6.0.26\\webapps\\uphold"
	 */
	protected String getRealPath(){
		return this.getRequest().getRealPath("");
	}
	
	protected HttpServletRequest getRequest()
	{
		return ServletActionContext.getRequest();
	}

	/**
	 * Convenience method to get the response
	 * 
	 * @return current response
	 */
	protected HttpServletResponse getResponse()
	{
		return ServletActionContext.getResponse();
	}

	/**
	 * Convenience method to get the session. This will create a session if one
	 * doesn't exist.
	 * 
	 * @return the session from the request (request.getSession()).
	 */
	protected HttpSession getSession()
	{
		return getRequest().getSession();
	}
	public void setResponse(HttpServletResponse response) {
		this.response = response;
	}

	public void setRequest(HttpServletRequest request) {
		this.request = request;
	}

	public void setSession(HttpSession session) {
		this.session = session;
	}

	public String getPager() {
		return pager;
	}

	public void setPager(String pager) {
		this.pager = pager;
	}
	

}
